home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / jade / src / stripproto.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  92 lines

  1. /* stripproto.c -- Program to strip `_PR' lines from C source
  2.    Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4.    This file is part of Jade.
  5.  
  6.    Jade is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    Jade is distributed in the hope that it will be useful, but
  12.    WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with Jade; see the file COPYING.    If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. extern void exit(int);
  24.  
  25. static void
  26. usage(void)
  27. {
  28.     fputs("usage: stripproto [-o dest-file] [src-files...]\n", stderr);
  29.     exit(1);
  30. }
  31.  
  32. static void
  33. scanfile(FILE *file)
  34. {
  35.     char buf[512];
  36.     while(fgets(buf, 512, file))
  37.     {
  38.     if((buf[0] == '_') && (buf[1] == 'P') && (buf[2] == 'R'))
  39.         fputs(buf, stdout);
  40.     }
  41. }
  42.  
  43. int
  44. main(int ac, char **av)
  45. {
  46.     ac--;
  47.     av++;
  48.     while(ac && (**av == '-'))
  49.     {
  50.     switch((*av)[1])
  51.     {
  52.     case 'o':
  53.         ac--;
  54.         av++;
  55.         if(!ac)
  56.         usage();
  57.         if(!freopen(*av, "w", stdout))
  58.         {
  59.         perror("freopen");
  60.         exit(5);
  61.         }
  62.         break;
  63.     case '-':
  64.         ac--;
  65.         av++;
  66.         goto endopts;
  67.     default:
  68.         usage();
  69.     }
  70.     ac--;
  71.     av++;
  72.     }
  73. endopts:
  74.     if(!ac)
  75.     scanfile(stdin);
  76.     else
  77.     {
  78.     while(ac)
  79.     {
  80.         FILE *file = fopen(*av, "r");
  81.         if(file)
  82.         {
  83.         scanfile(file);
  84.         fclose(file);
  85.         }
  86.         ac--;
  87.         av++;
  88.     }
  89.     }
  90.     exit(0);
  91. }
  92.